import './login.less'
import {Button, message ,Form, Input} from 'antd';
import {router} from "../../view/router/index.jsx";
import {setToken} from "../../view/uitls/token.js";
const token = new Date().getTime()
export default function Login() {
    const [form] = Form.useForm();
    const [messageApi, contextHolder] = message.useMessage();
    const success = () => {
        messageApi.open({
            type: 'success',
            content: '登录成功',
        });
    };
    const onFinish = (values) =>{
       const {useName, password} = values;
       if (useName === 'admin' && password === '123456'){
           setToken(token)
           success()
           setTimeout(()=>{
               router.navigate('/')
               form.resetFields()
           },2000)

       }
    }

    const onReset = () =>{
        form.resetFields();
    }
    return (
        <div className='login-content f-center'>
            <div className="login-form">
                {contextHolder}
                <Form
                    form={form}
                    onFinish={onFinish}>
                    <Form.Item label='账号' name='useName'>
                        <Input placeholder='请输入账号'/>
                    </Form.Item>
                    <Form.Item label='密码' name='password'>
                        <Input placeholder='请输入密码' />
                    </Form.Item>
                    <Form.Item>
                        <Button
                            type="primary"
                            className='mr8'
                            htmlType="submit">
                            登录
                        </Button>
                        <Button
                            onClick={onReset}>
                            重置
                        </Button>
                    </Form.Item>
                </Form>
            </div>
        </div>
    )
}
